package com.example.park2212.points

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.example.lib_base.entity.PointsBeanItemItem
import com.example.lib_base.mvvm.BaseActivity
import com.example.park2212.R
import com.example.park2212.databinding.ActivityTaskDetailBinding
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
@Route(path = "/app/points/TaskDetailActivity")
class TaskDetailActivity : BaseActivity<ActivityTaskDetailBinding,PointsViewModel>() {
    @Autowired
    lateinit var tid:String
    val list = mutableListOf<PointsBeanItemItem>()
    lateinit var patroLocationAdapter: PatroLocationAdapter
    override fun initView() {
        viewModel.getTaskById(tid.toInt())
        ARouter.getInstance().inject(this)

        patroLocationAdapter = PatroLocationAdapter()
        binding.taskDetailRv.apply {
            adapter = patroLocationAdapter
            layoutManager = LinearLayoutManager(this@TaskDetailActivity)

        }


    }

    override fun initData() {
        viewModel.getPointById.observe(this){
            Log.i("sss",it.toString())
            //list.add(it)
            patroLocationAdapter.addData(it)
            patroLocationAdapter.notifyDataSetChanged()
        }

        viewModel.getTaskByIdSuccess.observe(this){
            binding.taskDetailName.setText(it.taskName)
            binding.taskDetailTime.setText(it.patrolTime)
            it.patrolPoints.forEach {
                viewModel.getPointsById(it)
            }
        }
    }

}